<template>
  <div class="home-page">
    <div class="header">
      <div class="logo">
        <img src="@/assets/images/logo.svg" alt="" />
      </div>

      <div class="handler">
        <div class="to-shop btn" @click="toShop">
          <img src="@/assets/images/imgGemSquare.png" alt="" />

          <span>Shop</span>
        </div>

        <!-- <div class="login-btn btn">Login</div> -->

        <div class="user" @click="visible">
          <img v-if="userRows.photoUrl" :src="userRows.photoUrl" alt="" />
          <img v-else src="@/assets/images/user-avatar-fill.svg" alt="" />
          <div class="word">{{ userRows.username }}</div>
        </div>
      </div>
    </div>

    <div class="diy-popup">
      <van-popup v-model:show="show" @click-overlay="visible" position="bottom">
        <div class="user-info">
          <div class="avatar">
            <img src="@/assets/images/avatar-w.svg" alt="" />
          </div>

          <div class="info">
            <div class="name">
              {{ userRows.lastName + " " + userRows.firstName }}
            </div>

            <div class="country">
              <div class="box">
                <img src="@/assets/images/uk.svg" alt="" />

                <span class="word">UK</span>
              </div>

              <div class="line">|</div>

              <div class="box">
                <img src="@/assets/images/male.svg" alt="" />

                <img src="@/assets/images/female.svg" alt="" />

                <span class="word">Male</span>
              </div>
            </div>
          </div>
        </div>

        <div class="handle-list">
          <div class="item">
            <img src="@/assets/images/Edit.svg" alt="" />

            <span class="word">Edit Profile</span>
          </div>

          <div class="item" @click="toStartLive">
            <img src="@/assets/images/set.svg" alt="" />

            <span class="word">Start Live</span>
          </div>

          <!-- <div class="item">
            <img src="@/assets/images/logout.svg" alt="" />

            <span class="word">LogOut</span>
          </div> -->
        </div>
      </van-popup>
    </div>
    <slot />
  </div>
  <Navigation />
</template>

<script setup lang="ts">
import Navigation from "./Navigation.vue";
import { ref } from "vue";
import { initData, useSignal } from "@telegram-apps/sdk-vue";
import { useRouter } from "vue-router";

defineProps<{ title: string; disclaimer?: string }>();

const initDataRef = useSignal(initData.state);
const user = initDataRef.value?.user;

const userRows = user ? JSON.parse(JSON.stringify(user)) : {};

localStorage.setItem('info', userRows)

console.log(userRows);

const show = ref(false);
const visible = () => {
  show.value = !show.value;
};

const router = useRouter();
const toShop = () => {
  router.push({ name: "Shop" });
};

const toStartLive = () => {
  // role 角色：主播，观众
  router.push({ name: "LiveRoom", params: { id: "0001" }, query: { role: 'host' } });
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 10px 15px;
  height: 52px;
  // background: transparent;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0));
  // background: linear-gradient(to right, #8e44ad, #3498db);
  color: white;
  font-size: 24px;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  .logo {
    display: flex;
    height: 32px;
    flex-direction: column;
    justify-content: center;
    img {
      height: 24px;
    }
  }
  .handler {
    display: flex;
    .to-shop {
      display: flex;
      justify-content: center;
      margin-right: 15px;
      font-weight: bold;
      img {
        height: 20px;
        margin-top: 6px;
        margin-right: 2px;
      }
    }
    .login-btn {
    }
    .user {
      height: 32px;
      border-radius: 16px;
      background: #fff;
      font-size: 12px;
      color: #000;
      line-height: 32px;
      font-weight: bold;
      display: flex;
      padding: 0 3px;
      .word {
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      img {
        width: 26px;
        height: 26px;
        margin-top: 3px;
        margin-right: 5px;
        border-radius: 100%;
      }
    }
  }
}
.diy-popup {
  --van-popup-background: #333333;
  .van-overlay {
    background: rgba(0, 0, 0, 0.1);
  }
  .van-popup {
    border-radius: 15px 15px 0 0;
    overflow: hidden;
    .user-info {
      padding: 15px 15px;
      display: flex;
      border-bottom: 1px solid rgb(68, 68, 68);
      .avatar {
        width: 44px;
        height: 44px;
        border-radius: 100%;
        overflow: hidden;
        display: flex;
        margin-right: 10px;
        img {
          width: 44px;
          height: 44px;
          border-radius: 100%;
        }
      }
      .info {
        display: flex;
        flex-direction: column;
        height: 44px;
        justify-content: center;
        .name {
          line-height: 20px;
        }
        .country {
          display: flex;
          margin: 0 0;
          line-height: 20px;
          .box {
            display: flex;
            .word {
              font-size: 10px;
              line-height: 20px;
            }
          }
          .line {
            color: #fff;
            font-size: 10px;
            margin: 0 5px;
          }
        }
      }
    }
    .handle-list {
      padding: 10px 30px;
      .item {
        display: flex;
        line-height: 32px;
        margin: 15px 0;
        img {
          width: 20px;
          height: 20px;
          margin-right: 15px;
          margin-top: 6px;
        }
        .word {
          color: #fff;
          font-weight: bold;
        }
      }
    }
  }
}
</style>
